import axios from 'axios'
import md5 from 'js-md5';
import { formatDate } from '../common/util.js'
// import Vue from 'vue'
// import router from '../router';

// import qs from 'qs'
//加密

axios.defaults.timeout = 100000;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// 返回一个Promise(发送post请求)
export default {
    //get请求
    get(url, param) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'get',
                url,
                params: param,
            }).then(res => {
                if(res.data.code!=200) {
                    layer.msg(res.data.message);
                }
                resolve(res.data)    
            }).catch(e => {
                reject(e)
            }) 
        })
    },
    //post请求
    post(url, param) {
        return new Promise((resolve, reject) => {
            axios.defaults.headers.common['C-DG-TOKEN'] = md5('wquy76ewiuqwerfghjyu12oopiumnbvg' + formatDate(new Date(),3))
            axios.defaults.headers.common['C-DG-TIME'] = formatDate(new Date(),3)
            axios({
                method: 'post',
                url,
                data: param,
            }).then(res => {
                if(res.data.code!=200) {
                    // layer.msg(res.data.message);
                }
                resolve(res.data)
            }).catch(e => {
                reject(e)
            })
        })
    }
}